
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>代码生成 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-codeblock-label/block.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-click-reveal/click_reveal.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="part4-1-task.html" />
    
    
    <link rel="prev" href="part0-intro.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    实验简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../log.html">
            
                <a href="../log.html">
            
                    
                    更新日志
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">零：前置准备</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    配环境、跑测试
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../lab0/env.html">
            
                <a href="../lab0/env.html">
            
                    
                    环境配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../lab0/testing.html">
            
                <a href="../lab0/testing.html">
            
                    
                    运行测试样例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../lab0/riscv.html">
            
                <a href="../lab0/riscv.html">
            
                    
                    RISC-V 的工具链使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第一个编译器</li>
        
        
    
        <li class="chapter " data-level="3.1" >
            
                <span>
            
                    
                    step1：仅一个 return 的 main 函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../lab1/part1.html">
            
                <a href="../lab1/part1.html">
            
                    
                    从零开始的 lexer、parser 以及汇编生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../lab1/part2.html">
            
                <a href="../lab1/part2.html">
            
                    
                    词法语法分析工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../lab1/part3.html">
            
                <a href="../lab1/part3.html">
            
                    
                    使用中间码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.4.1" data-path="../lab1/antlr.html">
            
                <a href="../lab1/antlr.html">
            
                    
                    ANTLR 使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.2" data-path="../lab1/visitor.html">
            
                <a href="../lab1/visitor.html">
            
                    
                    Visitor 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.3" data-path="../lab1/ir.html">
            
                <a href="../lab1/ir.html">
            
                    
                    IR 简明介绍
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../lab1/spec.html">
            
                <a href="../lab1/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">常量表达式</li>
        
        
    
        <li class="chapter " data-level="4.1" >
            
                <span>
            
                    
                    step2：一元操作
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../lab2/intro.html">
            
                <a href="../lab2/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../lab2/guide.html">
            
                <a href="../lab2/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../lab2/spec.html">
            
                <a href="../lab2/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" >
            
                <span>
            
                    
                    step3：加减乘除模
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../lab3/intro.html">
            
                <a href="../lab3/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../lab3/guide.html">
            
                <a href="../lab3/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.3" data-path="../lab3/spec.html">
            
                <a href="../lab3/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" >
            
                <span>
            
                    
                    step4：比较和逻辑表达式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="../lab4/intro.html">
            
                <a href="../lab4/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.2" data-path="../lab4/guide.html">
            
                <a href="../lab4/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="../lab4/spec.html">
            
                <a href="../lab4/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">变量和语句</li>
        
        
    
        <li class="chapter " data-level="5.1" >
            
                <span>
            
                    
                    step5：局部变量和赋值
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../lab5/intro.html">
            
                <a href="../lab5/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../lab5/guide.html">
            
                <a href="../lab5/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.3.1" data-path="../lab5/stackframe.html">
            
                <a href="../lab5/stackframe.html">
            
                    
                    栈帧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.4" data-path="../lab5/spec.html">
            
                <a href="../lab5/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.2" >
            
                <span>
            
                    
                    step6：if 语句和条件表达式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.2.1" data-path="../lab6/intro.html">
            
                <a href="../lab6/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2.2" data-path="../lab6/guide.html">
            
                <a href="../lab6/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2.3" data-path="../lab6/spec.html">
            
                <a href="../lab6/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">块语句和作用域和更多语句</li>
        
        
    
        <li class="chapter " data-level="6.1" >
            
                <span>
            
                    
                    step7：作用域和块语句
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1.1" data-path="../lab7/intro.html">
            
                <a href="../lab7/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2" data-path="../lab7/guide.html">
            
                <a href="../lab7/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.3" data-path="../lab7/spec.html">
            
                <a href="../lab7/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6.2" >
            
                <span>
            
                    
                    step8：循环语句
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.2.1" data-path="../lab8/intro.html">
            
                <a href="../lab8/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2.2" data-path="../lab8/guide.html">
            
                <a href="../lab8/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2.3" data-path="../lab8/spec.html">
            
                <a href="../lab8/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">函数和全局变量</li>
        
        
    
        <li class="chapter " data-level="7.1" >
            
                <span>
            
                    
                    step9：函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="../lab9/intro.html">
            
                <a href="../lab9/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="../lab9/guide.html">
            
                <a href="../lab9/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.3.1" data-path="../lab9/calling.html">
            
                <a href="../lab9/calling.html">
            
                    
                    函数调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.4" data-path="../lab9/spec.html">
            
                <a href="../lab9/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" >
            
                <span>
            
                    
                    step10：全局变量
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.2.1" data-path="../lab10/part0-intro.html">
            
                <a href="../lab10/part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.2" data-path="../lab10/part1-parser.html">
            
                <a href="../lab10/part1-parser.html">
            
                    
                    词法语法分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.3" data-path="../lab10/part1-1-task.html">
            
                <a href="../lab10/part1-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.4" data-path="../lab10/part4-codegen.html">
            
                <a href="../lab10/part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.5" data-path="../lab10/part4-1-task.html">
            
                <a href="../lab10/part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.6" data-path="../lab10/summary.html">
            
                <a href="../lab10/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.7" data-path="../lab10/spec.html">
            
                <a href="../lab10/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">指针和数组</li>
        
        
    
        <li class="chapter " data-level="8.1" >
            
                <span>
            
                    
                    step11：指针
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1.1" data-path="../lab11/part0-intro.html">
            
                <a href="../lab11/part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.2" data-path="../lab11/typeck.html">
            
                <a href="../lab11/typeck.html">
            
                    
                    类型检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.3" data-path="../lab11/part4-codegen.html">
            
                <a href="../lab11/part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.4" data-path="../lab11/part4-1-task.html">
            
                <a href="../lab11/part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.5" data-path="../lab11/summary.html">
            
                <a href="../lab11/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.6" data-path="../lab11/spec.html">
            
                <a href="../lab11/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8.2" >
            
                <span>
            
                    
                    step12：数组
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.2.1" data-path="part0-intro.html">
            
                <a href="part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="8.2.2" data-path="part4-codegen.html">
            
                <a href="part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.3" data-path="part4-1-task.html">
            
                <a href="part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.4" data-path="summary.html">
            
                <a href="summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.5" data-path="spec.html">
            
                <a href="spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">参考资料</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../../REFERENCE.html">
            
                <a href="../../REFERENCE.html">
            
                    
                    参考资料
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >代码生成</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4EE3;&#x7801;&#x751F;&#x6210;">&#x4EE3;&#x7801;&#x751F;&#x6210;</h2>
<h3 id="&#x6570;&#x7EC4;&#x5B9A;&#x4E49;">&#x6570;&#x7EC4;&#x5B9A;&#x4E49;</h3>
<p>&#x6570;&#x636E;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x662F;&#x8FDE;&#x7EED;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x65E0;&#x8BBA;&#x6570;&#x7EC4;&#x7684;&#x539F;&#x578B;&#x662F;&#x51E0;&#x7EF4;&#x7684;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x770B;&#x505A;&#x662F;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x7684;&#x5927;&#x6570;&#x7EC4;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x6570;&#x7EC4; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mrow><mi mathvariant="monospace">i</mi><mi mathvariant="monospace">n</mi><mi mathvariant="monospace">t</mi></mrow><mtext>&#xA0;</mtext><mi>a</mi><mo>[</mo><msub><mi>d</mi><mn>1</mn></msub><mo>]</mo><mo>[</mo><msub><mi>d</mi><mn>2</mn></msub><mo>]</mo><mo>&#x22EF;</mo><mo>[</mo><msub><mi>d</mi><mi>n</mi></msub><mo>]</mo></mrow><annotation encoding="application/x-tex">\mathtt{int}~a[d_1][d_2]\cdots[d_n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord textstyle uncramped"><span class="mord mathtt">i</span><span class="mord mathtt">n</span><span class="mord mathtt">t</span></span><span class="mord mathit"><span class="mspace">&#xA0;</span><span class="mord mathit">a</span></span><span class="mopen">[</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">1</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span><span class="mopen">[</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span><span class="minner">&#x22EF;</span><span class="mopen">[</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span></span></span></span>&#xFF0C;&#x53EF;&#x770B;&#x505A;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mrow><mi mathvariant="monospace">i</mi><mi mathvariant="monospace">n</mi><mi mathvariant="monospace">t</mi></mrow><mtext>&#xA0;</mtext><msup><mi>a</mi><mrow><mi mathvariant="normal">&#x2032;</mi></mrow></msup><mo>[</mo><msub><mi>d</mi><mn>1</mn></msub><msub><mi>d</mi><mn>2</mn></msub><mo>&#x22EF;</mo><msub><mi>d</mi><mi>n</mi></msub><mo>]</mo></mrow><annotation encoding="application/x-tex">\mathtt{int}~a&apos;[d_1d_2\cdots d_n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.751892em;"></span><span class="strut bottom" style="height:1.001892em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord textstyle uncramped"><span class="mord mathtt">i</span><span class="mord mathtt">n</span><span class="mord mathtt">t</span></span><span class="mord"><span class="mspace">&#xA0;</span><span class="mord mathit">a</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord scriptstyle uncramped mtight"><span class="mord mathrm mtight">&#x2032;</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mopen">[</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">1</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="minner">&#x22EF;</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span></span></span></span>&#x3002;&#x8BBF;&#x95EE; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>a</mi><mo>[</mo><msub><mi>i</mi><mn>1</mn></msub><mo>]</mo><mo>[</mo><msub><mi>i</mi><mn>2</mn></msub><mo>]</mo><mo>&#x22EF;</mo><mo>[</mo><msub><mi>i</mi><mi>n</mi></msub><mo>]</mo></mrow><annotation encoding="application/x-tex">a[i_1][i_2]\cdots[i_n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">a</span><span class="mopen">[</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">1</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span><span class="mopen">[</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span><span class="minner">&#x22EF;</span><span class="mopen">[</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span></span></span></span>&#xFF0C;&#x5C31;&#x662F;&#x8BBF;&#x95EE; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msup><mi>a</mi><mrow><mi mathvariant="normal">&#x2032;</mi></mrow></msup><mo>[</mo><msub><mi>i</mi><mn>1</mn></msub><msub><mi>d</mi><mn>2</mn></msub><msub><mi>d</mi><mn>3</mn></msub><mo>&#x22EF;</mo><msub><mi>d</mi><mi>n</mi></msub><mo>+</mo><msub><mi>i</mi><mn>2</mn></msub><msub><mi>d</mi><mn>3</mn></msub><msub><mi>d</mi><mn>4</mn></msub><mo>&#x22EF;</mo><msub><mi>d</mi><mi>n</mi></msub><mo>+</mo><mo>&#x22EF;</mo><mo>+</mo><msub><mi>i</mi><mi>n</mi></msub><mo>]</mo></mrow><annotation encoding="application/x-tex">a&apos;[i_1d_2d_3\cdots d_n + i_2d_3d_4\cdots d_n + \cdots + i_n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.751892em;"></span><span class="strut bottom" style="height:1.001892em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathit">a</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord scriptstyle uncramped mtight"><span class="mord mathrm mtight">&#x2032;</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mopen">[</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">1</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">3</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="minner">&#x22EF;</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mbin">+</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">3</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathrm mtight">4</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="minner">&#x22EF;</span><span class="mord"><span class="mord mathit">d</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mbin">+</span><span class="minner">&#x22EF;</span><span class="mbin">+</span><span class="mord"><span class="mord mathit">i</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span><span class="mclose">]</span></span></span></span>&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x8003;&#x8651;&#x5B9A;&#x4E49;&#x6570;&#x7EC4;&#x65F6;&#xFF0C;&#x662F;&#x4F5C;&#x4E3A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x8FD8;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF1A;</p>
<p>&#x5F53;&#x67D0;&#x4E2A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x4E3A;&#x6570;&#x7EC4;&#x65F6;&#xFF0C;&#x6570;&#x7EC4;&#x7A7A;&#x95F4;&#x5206;&#x914D;&#x5728;&#x6808;&#x4E0A;&#x3002;&#x8FD9;&#x4E0E;&#x666E;&#x901A;&#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;&#x57FA;&#x672C;&#x6CA1;&#x533A;&#x522B;&#xFF0C;&#x540C;&#x6837;&#x9700;&#x8981;&#x7B97;&#x51FA;&#x5728;&#x6808;&#x5E27;&#x4E0A;&#x7684;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x53EA;&#x4E0D;&#x8FC7;&#x5927;&#x5C0F;&#x4E0D;&#x518D;&#x662F;&#x56FA;&#x5B9A;&#x7684; 4 &#x5B57;&#x8282;&#xFF0C;&#x800C;&#x662F;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;&#x518D;&#x4E58; 4 (&#x5B57;&#x8282;/&#x5143;&#x7D20;)&#xFF0C;&#x56E0;&#x6B64;&#x8BA1;&#x7B97;&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#x7684;&#x504F;&#x79FB;&#x91CF;&#x65F6;&#x4E5F;&#x8981;&#x505A;&#x76F8;&#x5E94;&#x4FEE;&#x6539;&#x3002;&#x7531;&#x4E8E;&#x4E0D;&#x652F;&#x6301;&#x6570;&#x7EC4;&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5206;&#x914D;&#x5B8C;&#x6808;&#x5E27;&#x540E;&#x4E0D;&#x7528;&#x7BA1;&#x5B83;&#x5C31;&#x884C;&#xFF0C;&#x5373;&#x4F7F;&#x8FD9;&#x6BB5;&#x6808;&#x7A7A;&#x95F4;&#x4FDD;&#x7559;&#x4E86;&#x4E4B;&#x524D;&#x53D8;&#x91CF;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x56E0;&#x6B64;&#x6570;&#x7EC4;&#x8FD8;&#x6709;&#x5176;&#x4ED6;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x7684;&#x521D;&#x503C;&#x90FD;&#x662F;&#x4E0D;&#x786E;&#x5B9A;&#x7684;&#x3002;</p>
<p>&#x5F53;&#x67D0;&#x4E2A;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x4E3A;&#x6570;&#x7EC4;&#x65F6;&#xFF0C;&#x6570;&#x7EC4;&#x7A7A;&#x95F4;&#x5206;&#x914D;&#x5728;&#x7A0B;&#x5E8F;&#x7684;&#x6570;&#x636E;&#x6BB5;&#x3002;&#x540C;&#x6837;&#x6211;&#x4EEC;&#x4E0D;&#x8003;&#x8651; BSS &#x6BB5;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;&#x5176;&#x653E;&#x5230; .data &#x4E2D;&#x3002;&#x4F5C;&#x4E3A;&#x5168;&#x90E8;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x9ED8;&#x8BA4;&#x521D;&#x59CB;&#x5316;&#x4E3A; 0&#xFF0C;&#x53EF;&#x7528;&#x5982;&#x4E0B;&#x6C47;&#x7F16;&#x7801;&#x6765;&#x5C06;&#x8FDE;&#x7EED;&#x4E00;&#x6BB5;&#x5185;&#x5B58;&#x521D;&#x59CB;&#x5316;&#x4E3A; 0&#xFF1A;</p>
<pre><code class="lang-asm">    .align 2
a:
    .zero 400
</code></pre>
<p>&#x5176;&#x4E2D; <code>.zero</code> &#x540E;&#x9762;&#x7684;&#x6570;&#x5B57;&#x5373;&#x8FD9;&#x6BB5;&#x5185;&#x5B58;&#x7684;&#x5927;&#x5C0F;&#xFF08;&#x5355;&#x4F4D;&#x5B57;&#x8282;&#xFF09;&#x3002;&#x4E0A;&#x8FF0;&#x6C47;&#x7F16;&#x7801;&#x53EF;&#x7531;&#x5B9A;&#x4E49;&#x5728;&#x5168;&#x5C40;&#x7684; <code>int a[100];</code> &#x6216; <code>int a[10][10];</code> &#x751F;&#x6210;&#x3002;</p>
<blockquote>
<p>&#x5728; RISC-V &#x6307;&#x4EE4;&#x96C6;&#x4E2D;&#xFF0C;<code>addi</code>&#x3001;<code>lw</code>&#x3001;<code>sw</code> &#x7B49; I &#x578B;&#x548C; S &#x578B;&#x6307;&#x4EE4;&#x7684;&#x7ACB;&#x5373;&#x6570;&#x5927;&#x5C0F;&#x53EA;&#x6709; 12 &#x4F4D;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x4E0D;&#x80FD;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5F88;&#x5927;&#x7684;&#x6570;&#x7EC4;&#x4F5C;&#x4E3A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x5426;&#x5219;&#x90A3;&#x4E9B;&#x5206;&#x914D;&#x6808;&#x5E27;&#x3001;Load/Store &#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x7684;&#x6307;&#x4EE4;&#x7684;&#x504F;&#x79FB;&#x91CF;&#x5C31;&#x4F1A;&#x8D85;&#x51FA; 12 &#x4F4D;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5BF9;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x7684;&#x7279;&#x6B8A;&#x5904;&#x7406;&#xFF0C;&#x4F7F;&#x7528;&#x5176;&#x4ED6;&#x6307;&#x4EE4;&#x8FDB;&#x884C;&#x4EE3;&#x66FF;&#xFF0C;&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x7684;&#x6D4B;&#x8BD5;&#x96C6;&#x4FDD;&#x8BC1;&#x4E86;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x3002;</p>
</blockquote>
<h3 id="&#x4E0B;&#x6807;&#x8FD0;&#x7B97;">&#x4E0B;&#x6807;&#x8FD0;&#x7B97;</h3>
<h4 id="&#x6307;&#x9488;&#x4E0B;&#x6807;">&#x6307;&#x9488;&#x4E0B;&#x6807;</h4>
<p>&#x6211;&#x4EEC;&#x5141;&#x8BB8;&#x5BF9;&#x6307;&#x9488;&#x548C;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x8FDB;&#x884C;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x3002;&#x9996;&#x5148;&#x6765;&#x770B;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x3002;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x975E;&#x5E38;&#x7C7B;&#x4F3C;&#x4E8E;&#x89E3;&#x5F15;&#x7528;&#x8FD0;&#x7B97; <code>*</code>&#xFF0C;&#x53EA;&#x662F;&#x9700;&#x8981;&#x52A0;&#x4E0A;&#x4E00;&#x4E2A;&#x504F;&#x79FB;&#xFF0C;&#x5927;&#x5C0F;&#x4E3A;&#x4E0B;&#x6807;&#x4E58;&#x4E0A;&#x6307;&#x9488;&#x57FA;&#x7C7B;&#x578B;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x5373; <code>p[i]</code> &#x7B49;&#x4EF7;&#x4E8E; <code>*(p + i * size)</code>&#x3002;&#x53E6;&#x5916;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF0C;&#x6211;&#x4EEC;&#x5728; lab11 &#x4E2D;&#x63D0;&#x5230;&#x4E86;&#x5DE6;&#x503C;&#x7684;&#x6982;&#x5FF5;&#xFF0C;<code>*</code> &#x8FD0;&#x7B97;&#x540E;&#x7684;&#x7ED3;&#x679C;&#x53EF;&#x4EE5;&#x662F;&#x5DE6;&#x503C;&#xFF0C;&#x7C7B;&#x4F3C;&#x5730;&#xFF0C;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x5DE6;&#x503C;&#xFF1A;</p>
<pre><code class="lang-c"><span class="hljs-keyword">int</span> *p;
p[<span class="hljs-number">0</span>] = <span class="hljs-number">1</span>;       <span class="hljs-comment">// p[0] &#x662F;&#x5DE6;&#x503C;</span>
<span class="hljs-keyword">int</span> a = p[<span class="hljs-number">1</span>];   <span class="hljs-comment">// p[1] &#x662F;&#x53F3;&#x503C;</span>
<span class="hljs-keyword">int</span> *q = &amp;p[<span class="hljs-number">2</span>]; <span class="hljs-comment">// p[2] &#x662F;&#x5DE6;&#x503C;</span>
</code></pre>
<p>&#x4E8E;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x6309;&#x7167;&#x5B9E;&#x73B0;&#x89E3;&#x5F15;&#x7528;&#x8FD0;&#x7B97;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5373;&#x53EF;&#x5B9E;&#x73B0;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x3002;</p>
<h4 id="&#x6570;&#x7EC4;&#x4E0B;&#x6807;">&#x6570;&#x7EC4;&#x4E0B;&#x6807;</h4>
<p>&#x7136;&#x540E;&#x518D;&#x6765;&#x770B;&#x6570;&#x7EC4;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x3002;&#x6570;&#x7EC4;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x53EF;&#x4EE5;&#x5206;&#x4E3A;&#x4E24;&#x7C7B;&#xFF1A;</p>
<ol>
<li>&#x5F53;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x7684;&#x6B21;&#x6570;&#x7B49;&#x4E8E;&#x6570;&#x7EC4;&#x7684;&#x7EF4;&#x5EA6;&#x65F6;&#xFF0C;&#x7ED3;&#x679C;&#x662F;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x3002;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0E;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x7C7B;&#x4F3C;&#xFF0C;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x53F3;&#x503C;&#xFF0C;&#x7ED3;&#x679C;&#x662F;&#x6570;&#x7EC4;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x503C;&#xFF1B;&#x4E5F;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x5DE6;&#x503C;&#xFF0C;&#x7ED3;&#x679C;&#x662F;&#x6570;&#x7EC4;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x5730;&#x5740;&#x3002;</li>
<li>&#x5F53;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x7684;&#x6B21;&#x6570;&#x5C0F;&#x4E8E;&#x6570;&#x7EC4;&#x7684;&#x7EF4;&#x5EA6;&#x65F6;&#xFF0C;&#x7ED3;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x3002;&#x7531;&#x4E8E;&#x4EFB;&#x4F55;&#x6570;&#x7EC4;&#x53EF;&#x770B;&#x505A;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x5927;&#x6570;&#x7EC4;&#xFF0C;&#x6B64;&#x65F6;&#x7684;&#x7ED3;&#x679C;&#x4E5F;&#x53EF;&#x4EE5;&#x770B;&#x505A;&#x662F;&#x539F;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x6570;&#x7EC4;&#x3002;&#x5F53;&#x4E4B;&#x540E;&#x5BF9;&#x8BE5;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x8F6C;&#x6307;&#x9488;&#x3001;&#x53D6;&#x4E0B;&#x6807;&#x7B49;&#x8FD0;&#x7B97;&#x65F6;&#xFF0C;&#x90FD;&#x662F;&#x76F8;&#x5BF9;&#x4E8E;&#x8FD9;&#x4E2A;&#x5B50;&#x6570;&#x7EC4;&#x6765;&#x8BF4;&#x7684;&#x3002;&#x4E4B;&#x540E;&#x8981;&#x53D6;&#x5B50;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x54EA;&#x4E2A;&#x5143;&#x7D20;&#x73B0;&#x5728;&#x8FD8;&#x662F;&#x672A;&#x77E5;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x65E0;&#x8BBA;&#x4E4B;&#x540E;&#x662F;&#x5426;&#x6709;&#x53EF;&#x80FD;&#x6210;&#x4E3A;&#x5DE6;&#x503C;&#xFF0C;&#x8FD9;&#x4E00;&#x6B65;&#x90FD;&#x5E94;&#x8BE5;&#x8FD4;&#x56DE;&#x5B50;&#x6570;&#x7EC4;&#x7684;&#x5730;&#x5740;&#x3002;</li>
</ol>
<p>&#x5BF9;&#x4E8E;&#x7B2C; 1 &#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x4E0E;&#x6307;&#x9488;&#x7684;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x7C7B;&#x4F3C;&#x5904;&#x7406;&#xFF1B;&#x5BF9;&#x4E8E;&#x7B2C; 2 &#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x5173;&#x952E;&#x662F;&#x8981;&#x6C42;&#x51FA;&#x5B50;&#x6570;&#x7EC4;&#x7684;&#x5730;&#x5740;&#x3002;&#x7531;&#x4E8E;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x5728;&#x6587;&#x6CD5;&#x4E2D;&#x662F;&#x9012;&#x5F52;&#x5B9A;&#x4E49;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x81EA;&#x7136;&#x5730;&#x5F97;&#x51FA;&#x5730;&#x5740;&#x7684;&#x8BA1;&#x7B97;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li>&#x5BF9;&#x4E8E;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x7684;&#x53D8;&#x91CF; <code>Ident</code>&#xFF0C;&#x5730;&#x5740;&#x5373; <code>Ident</code> &#x5728;&#x6808;&#x6216;&#x6570;&#x636E;&#x6BB5;&#x7684;&#x5730;&#x5740;&#xFF1B;</li>
<li>&#x5BF9;&#x4E8E;&#x5B50;&#x6570;&#x7EC4; <code>array[i]</code>&#xFF0C;&#x5730;&#x5740;&#x662F; <code>array</code> &#x7684;&#x5730;&#x5740;&#x52A0;&#x4E0A; <code>i * sizeof(array[i])</code>&#x3002;</li>
</ul>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E;&#x6570;&#x7EC4; <code>int a[3][4][5]</code>&#xFF0C;&#x6709;&#xFF1A;</p>
<ul>
<li><code>a[i]</code> &#x7684;&#x5730;&#x5740;&#x662F; <code>a + (i * 4 * 5) * sizeof(int)</code>&#xFF1B;</li>
<li><code>a[i][j]</code> &#x7684;&#x5730;&#x5740;&#x662F; <code>a + [(i * 4 * 5) + (j * 5)] * sizeof(int)</code>&#xFF1B;</li>
<li><code>a[i][j][k]</code> &#x7684;&#x5730;&#x5740;&#x662F; <code>a + [(i * 4 * 5) + (j * 5) + k] * sizeof(int)</code>&#x3002;</li>
</ul>
<p>&#x603B;&#x7ED3;&#x4E00;&#x4E0B;&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x6307;&#x9488;&#x8FD8;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x5DE6;&#x503C;&#x8FD8;&#x662F;&#x53F3;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x90FD;&#x53EF;&#x4EE5;&#x7528;&#x540C;&#x4E00;&#x5957;&#x4EE3;&#x7801;&#x6846;&#x67B6;&#x6765;&#x751F;&#x6210;&#x6C47;&#x7F16;&#x7801;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">visitSubscript</span>(<span class="hljs-params">ctx</span>) </span>{          <span class="hljs-comment">// &lt;postfix&gt; ::= &lt;postfix&gt; &apos;[&apos; expr &apos;]&apos;</span>
    visitPostfix(postfix);              <span class="hljs-comment">// &#x8BA1;&#x7B97;&#x8981;&#x53D6;&#x4E0B;&#x6807;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x503C;&#xFF0C;&#x8BBE;&#x7ED3;&#x679C;&#x4FDD;&#x5B58;&#x5728; t0</span>
    visitExpr(expr);                    <span class="hljs-comment">// &#x8BA1;&#x7B97;&#x4E0B;&#x6807;&#x7684;&#x503C;&#xFF0C;&#x8BBE;&#x7ED3;&#x679C;&#x4FDD;&#x5B58;&#x5728; t1</span>
    emitMul(<span class="hljs-string">&quot;t1&quot;</span>, <span class="hljs-string">&quot;t1&quot;</span>, ctx.type.size); <span class="hljs-comment">// t1 = t1 * sizeof(&#x7ED3;&#x679C;&#x7684;&#x7C7B;&#x578B;)</span>
    emitAdd(<span class="hljs-string">&quot;t0&quot;</span>, <span class="hljs-string">&quot;t0&quot;</span>, <span class="hljs-string">&quot;t1&quot;</span>);          <span class="hljs-comment">// t0 = t0 + t1&#xFF0C;&#x6B64;&#x65F6;&#x7684;&#x7ED3;&#x679C;&#x5373;&#x4E0B;&#x6807;&#x8FD0;&#x7B97;&#x540E;&#x5B50;&#x6570;&#x7EC4;&#x6216;&#x5143;&#x7D20;&#x7684;&#x5730;&#x5740;</span>
    <span class="hljs-keyword">if</span> (ctx.type == <span class="hljs-built_in">Array</span> || ctx.isLValue) {
        <span class="hljs-comment">// do nothing                   // &#x5982;&#x679C;&#x7ED3;&#x679C;&#x662F;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#xFF0C;&#x6216;&#x662F;&#x5DE6;&#x503C;&#xFF0C;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x5176;&#x5730;&#x5740;</span>
    } <span class="hljs-keyword">else</span> {
        emitLoad();                     <span class="hljs-comment">// &#x5426;&#x5219;&#xFF0C;&#x518D;&#x751F;&#x6210;&#x4E00;&#x6761; Load &#x6307;&#x4EE4;&#x6765;&#x53D6;&#x51FA;&#x8BE5;&#x5730;&#x5740;&#x4E2D;&#x4FDD;&#x5B58;&#x7684;&#x503C;</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">visitPrimary</span>(<span class="hljs-params">ctx</span>) </span>{
    <span class="hljs-keyword">if</span> (ctx ::= Ident) {        <span class="hljs-comment">// &lt;primary&gt; ::= Identifier</span>
        emitAddress(Ident);     <span class="hljs-comment">// &#x8BA1;&#x7B97;&#x53D8;&#x91CF; Ident &#x7684;&#x5730;&#x5740;</span>
        <span class="hljs-keyword">if</span> (ctx.type == <span class="hljs-built_in">Array</span> || ctx.isLValue) {
            <span class="hljs-comment">// do nothing       // &#x5982;&#x679C;&#x53D8;&#x91CF;&#x662F;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#xFF0C;&#x6216;&#x662F;&#x5DE6;&#x503C;&#xFF0C;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x5176;&#x5730;&#x5740;</span>
        } <span class="hljs-keyword">else</span> {
            emitLoad();         <span class="hljs-comment">// &#x5426;&#x5219;&#xFF0C;&#x518D;&#x751F;&#x6210;&#x4E00;&#x6761; Load &#x6307;&#x4EE4;&#x6765;&#x53D6;&#x5F97;&#x53D8;&#x91CF;&#x7684;&#x503C;</span>
        }
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// ...</span>
    }
}
</code></pre>
<h3 id="&#x6307;&#x9488;&#x7B97;&#x672F;&#x8FD0;&#x7B97;">&#x6307;&#x9488;&#x7B97;&#x672F;&#x8FD0;&#x7B97;</h3>
<p>&#x8FD9;&#x4E00;&#x6B65;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x6211;&#x4EEC;&#x8981;&#x652F;&#x6301;&#x7684;&#x6240;&#x6709;&#x6307;&#x9488;&#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x5C31;&#x8FD9;&#x4E48;&#x591A;&#xFF1A;</p>
<ol>
<li>&#x6307;&#x9488;&#x52A0;&#x6574;&#x6570;&#xFF0C;&#x6216;&#x6574;&#x6570;&#x52A0;&#x6307;&#x9488;&#xFF1A;&#x53EA;&#x9700;&#x589E;&#x52A0;&#x4E00;&#x6B65;&#xFF0C;&#x5C06;&#x6574;&#x6570;&#x64CD;&#x4F5C;&#x6570;&#x4E58;&#x4E0A;&#x6307;&#x9488;&#x57FA;&#x7C7B;&#x578B;&#x7684;&#x5927;&#x5C0F;&#x3002;</li>
<li>&#x6307;&#x9488;&#x51CF;&#x6574;&#x6570;&#xFF1A;&#x4E0E;&#x6307;&#x9488;&#x52A0;&#x6CD5;&#x4E00;&#x6837;&#xFF0C;&#x53EA;&#x9700;&#x589E;&#x52A0;&#x4E00;&#x6B65;&#xFF0C;&#x5C06;&#x6574;&#x6570;&#x64CD;&#x4F5C;&#x6570;&#x4E58;&#x4E0A;&#x6307;&#x9488;&#x57FA;&#x7C7B;&#x578B;&#x7684;&#x5927;&#x5C0F;&#x3002;</li>
<li>&#x6307;&#x9488;&#x51CF;&#x6307;&#x9488;&#xFF1A;&#x5148;&#x76F4;&#x63A5;&#x505A;&#x51CF;&#x6CD5;&#xFF0C;&#x7136;&#x540E;&#x9664;&#x4EE5;&#x6307;&#x9488;&#x57FA;&#x7C7B;&#x578B;&#x7684;&#x5927;&#x5C0F;&#xFF08;&#x8981;&#x6C42;&#x4E24;&#x6307;&#x9488;&#x57FA;&#x7C7B;&#x578B;&#x76F8;&#x540C;&#xFF09;&#x3002;</li>
</ol>
<blockquote>
<p>&#x7531;&#x4E8E;&#x6307;&#x9488;&#x7684;&#x57FA;&#x7C7B;&#x578B;&#x53EA;&#x80FD;&#x662F; <code>int</code> &#x6216;&#x6307;&#x9488;&#xFF0C;&#x5176;&#x5927;&#x5C0F;&#x90FD;&#x662F; 4 &#x5B57;&#x8282;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7528; <code>slli</code>&#x3001;<code>srai</code> &#x6307;&#x4EE4;&#x8FDB;&#x884C;&#x5DE6;&#x79FB;&#x3001;&#x53F3;&#x79FB;&#x6765;&#x4EE3;&#x66FF;&#x4E58;&#x9664;&#x8FD0;&#x7B97;&#x3002;</p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="part0-intro.html" class="navigation navigation-prev " aria-label="Previous page: 摘要">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="part4-1-task.html" class="navigation navigation-next " aria-label="Next page: 任务">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"代码生成","level":"8.2.2","depth":2,"next":{"title":"任务","level":"8.2.3","depth":2,"path":"docs/lab12/part4-1-task.md","ref":"docs/lab12/part4-1-task.md","articles":[]},"previous":{"title":"摘要","level":"8.2.1","depth":2,"path":"docs/lab12/part0-intro.md","ref":"docs/lab12/part0-intro.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","mermaid-gb3","codeblock-label","code","search-pro","click-reveal","expandable-chapters-interactive","localized-footer"],"pluginsConfig":{"chapter-fold":{},"emphasize":{},"codeblock-label":{},"search-pro":{},"search":{},"localized-footer":{"filename":"gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":1},"click-reveal":{},"highlight":{},"mermaid-gb3":{},"expandable-chapters-interactive":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docs/lab12/part4-codegen.md","mtime":"2020-09-02T07:27:37.415Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-08T05:38:47.833Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-click-reveal/click_reveal.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

